package com.metacube.questionbank.jdbc;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.springframework.dao.DataAccessException;

import com.metacube.questionbank.dto.RecentQuestionDTO;

public class RecentQuestionExtractor {

RecentQuestionDTO rqDTO = new RecentQuestionDTO();
	
	public RecentQuestionDTO extractData(ResultSet res) throws SQLException, DataAccessException{
		
		try {
			rqDTO.getqDTO().setqId(res.getInt("QID"));
			rqDTO.getqDTO().setqAskedDate(res.getDate("QASKEDDATE"));
			rqDTO.getqDTO().setqTitle(res.getString("QTITLE"));
			rqDTO.getuDTO().setName(res.getString("USERNAME"));
			rqDTO.getuDTO().setPhotoURL(res.getString("PROFILEPICTURE"));
			rqDTO.getqDTO().setVoteLike(res.getInt("VOTELIKE"));
			rqDTO.setTotalAnswers(res.getInt("COUNT(A.AID)"));
		} catch (SQLException e) {
			
			System.out.println("Error While Set question data to list" + e.getMessage());
		}
		return rqDTO;	
	}
}
